/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ClassesJava;

import connexion.ConnectionManager;
import interface_graphique.Authentification;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author ISMAYLOULABBIHI
 */
public class Professeur extends Personne {
    
    private int id;
    private String matiere;
    public ConnectionManager c;
    
   public Professeur() {
        super();
        }

    
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getMatiere() {
        return matiere;
    }

    public void setMatiere(String matiere) {
        this.matiere = matiere;
    }
    

    public Professeur(int num, String nom, String prenom, String tel, String email,String mt) {
        super(nom, prenom, tel, email);

        this.id = num;
        this.matiere = mt;
        // TODO Auto-generated constructor stub
    }
   // private Professeur(int int, String string) {
    //     throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    // }
    public int ajouterProff(Professeur p) {
        int i;
        c = new ConnectionManager();
        String rq = "INSERT INTO  `gestion_des_emplois`.`profrsseurs` (idprof , nom , prenom,tel,email,matiere )"
                + " VALUES (NULL ,'" + p.getNom() + "', '" + p.getPrenom() + "','" + p.getTel() + "', '" + p.getEmail() + "')";
        i = c.setDataBase(rq);
        return i;
    }

    public int modifierProf(Professeur p) {
        int i = 0;
        c = new ConnectionManager();
        String rq = "UPDATE  `gestion_des_emplois`.`professeurs` SET `nom` = '" + p.getNom() + "', "
                + "`prenom` = '" + p.getPrenom() + "'," + "'tel'='" + p.getTel() + "',," + "'email'='" + p.getEmail() + "',where idprof=" + p.getId();
        i = c.setDataBase(rq);
        return i;
    }

    public int supprimerProf(Professeur p) {
        int i = 0;
        c = new ConnectionManager();
        String rq = "DELETE FROM `gestion_des_emplois`.`professeurs` where idprof=" + p.getId();
        i = c.setDataBase(rq);
        return i;
    }

    public void affectProf() {
    }


    public Vector<Professeur> getProfesseur() {
        Vector<Professeur> res = new Vector();
        try {
            c = new ConnectionManager();
            ResultSet rs = c.getDataBase("select p.idprof,p.nom,p.pernom,p.tel,p.email,m.label from professeurs p join matiere m on p.matiere=m.idM");

            while (rs.next()) {
                Professeur p = new Professeur(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5),rs.getString(6));
                System.err.println(rs.getString(6));
                res.add(p);
            }

        } catch (SQLException ex) {
            Logger.getLogger(Salle.class.getName()).log(Level.SEVERE, null, ex);
        }

        return res;
    }
    public Professeur getProfesseurById(int id){
        Professeur p = null;
        try {
            c = new ConnectionManager();
            ResultSet rs = c.getDataBase("select p.idprof,p.nom,p.pernom,p.tel,p.email,m.label from professeurs p "
                    + "join matiere m on p.matiere=m.idM where p.matiere="+id);

            while (rs.next()) {
                 p = new Professeur(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5),rs.getString(6));
                
            }

        } catch (SQLException ex) {
            Logger.getLogger(Salle.class.getName()).log(Level.SEVERE, null, ex);
        }

        return p;
    } 

     public Vector<Professeur> getProfesseurByMatieres(String matieres) {
        Vector<Professeur> res = new Vector();
        try {
            c = new ConnectionManager();
            ResultSet rs = c.getDataBase("SELECT * FROM professeurs WHERE matiere = (SELECT idM FROM matiere WHERE label='" + matieres +"')");
         
            while (rs.next()) {
                Professeur p = new Professeur(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5),rs.getString(6));
                System.err.println(rs.getInt(1));
                res.add(p);
            }

        } catch (SQLException ex) {
            Logger.getLogger(Salle.class.getName()).log(Level.SEVERE, null, ex);
        }

        return res;
    }

    public Vector<Professeur> getProfByMatieresByZone(String matiere, int col, int row) {
        Vector<Professeur> res = new Vector();
        try {
            c = new ConnectionManager();
            ResultSet rs = c.getDataBase("SELECT * FROM professeurs WHERE matiere = (SELECT idM FROM matiere WHERE label='" + matiere +"')"
                    + "and idprof not in (SELECT id_p FROM cours WHERE row="+row+" and col="+col+" and id_p is not null)");
         
            while (rs.next()) {
                Professeur p = new Professeur(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5),rs.getString(6));
                System.err.println(rs.getInt(1));
                res.add(p);
            }

        } catch (SQLException ex) {
            Logger.getLogger(Salle.class.getName()).log(Level.SEVERE, null, ex);
        }

        return res;  }
     
     

}
